<!DOCTYPE html>
<html lang=zh>
<head>
  <meta charset="utf-8">
  
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no, minimal-ui">
  <meta name="renderer" content="webkit">
  <meta http-equiv="Cache-Control" content="no-transform" />
  <meta http-equiv="Cache-Control" content="no-siteapp" />
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">
  <meta name="format-detection" content="telephone=no,email=no,adress=no">
  <!-- Color theme for statusbar -->
  <meta name="theme-color" content="#000000" />
  <!-- 强制页面在当前窗口以独立页面显示,防止别人在框架里调用页面 -->
  <meta http-equiv="window-target" content="_top" />
  
  
  <title>Docker 常用命令 | 知识是最有价值的东西</title>
  <meta name="description" content="查看命令查看 Docker 帮助命令：docker 或docker --help [jirenyoudeMacBook-Pro:~ jirry]$ docker --helpUsage:	docker [OPTIONS] COMMANDA self-sufficient runtime for containersOptions:      --config string      Locatio">
<meta property="og:type" content="article">
<meta property="og:title" content="Docker 常用命令">
<meta property="og:url" content="http:&#x2F;&#x2F;jirenyou.gitee.io&#x2F;blog&#x2F;2019&#x2F;12&#x2F;25&#x2F;docker&#x2F;docker-common&#x2F;index.html">
<meta property="og:site_name" content="知识是最有价值的东西">
<meta property="og:description" content="查看命令查看 Docker 帮助命令：docker 或docker --help [jirenyoudeMacBook-Pro:~ jirry]$ docker --helpUsage:	docker [OPTIONS] COMMANDA self-sufficient runtime for containersOptions:      --config string      Locatio">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2019-12-25T15:40:15.000Z">
<meta property="article:modified_time" content="2019-12-25T15:40:15.000Z">
<meta property="article:author" content="Jirry">
<meta property="article:tag" content="docker">
<meta name="twitter:card" content="summary">
  <!-- Canonical links -->
  <link rel="canonical" href="http://jirenyou.gitee.io/blog/2019/12/25/docker/docker-common/index.html">
  
    <link rel="alternate" href="/atom.xml" title="知识是最有价值的东西" type="application/atom+xml">
  
  
    <link rel="icon" href="/blog/favicon.ico" type="image/x-icon">
  
  
<link rel="stylesheet" href="/blog/css/style.css">

  
  
  
  
<meta name="generator" content="Hexo 4.1.0"></head>


<body class="main-center theme-black" itemscope itemtype="http://schema.org/WebPage">
  <header class="header" itemscope itemtype="http://schema.org/WPHeader">
  <div class="slimContent">
    <div class="navbar-header">
      
      
      <div class="profile-block text-center">
        <a id="avatar" href="https://jirenyou.gitee.io/blog" target="_blank">
          <img class="img-circle img-rotate" src="/blog/images/avatar.jpg" width="200" height="200">
        </a>
        <h2 id="name" class="hidden-xs hidden-sm">Jirry</h2>
        <h3 id="title" class="hidden-xs hidden-sm hidden-md">Back end development Architecture</h3>
        <small id="location" class="text-muted hidden-xs hidden-sm"><i class="icon icon-map-marker"></i> Shenzhen, China</small>
      </div>
      
      <div class="search" id="search-form-wrap">

    <form class="search-form sidebar-form">
        <div class="input-group">
            <input type="text" class="search-form-input form-control" placeholder="搜索" />
            <span class="input-group-btn">
                <button type="submit" class="search-form-submit btn btn-flat" onclick="return false;"><i class="icon icon-search"></i></button>
            </span>
        </div>
    </form>
    <div class="ins-search">
  <div class="ins-search-mask"></div>
  <div class="ins-search-container">
    <div class="ins-input-wrapper">
      <input type="text" class="ins-search-input" placeholder="想要查找什么..." x-webkit-speech />
      <button type="button" class="close ins-close ins-selectable" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
    </div>
    <div class="ins-section-wrapper">
      <div class="ins-section-container"></div>
    </div>
  </div>
</div>


</div>
      <button class="navbar-toggle collapsed" type="button" data-toggle="collapse" data-target="#main-navbar" aria-controls="main-navbar" aria-expanded="false">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
    </div>
    <nav id="main-navbar" class="collapse navbar-collapse" itemscope itemtype="http://schema.org/SiteNavigationElement" role="navigation">
      <ul class="nav navbar-nav main-nav ">
        
        
        <li class="menu-item menu-item-home">
          <a href="/blog/.">
            
            <i class="icon icon-home-fill"></i>
            
            <span class="menu-title">首页</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-archives">
          <a href="/blog/archives">
            
            <i class="icon icon-archives-fill"></i>
            
            <span class="menu-title">归档</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-categories">
          <a href="/blog/categories">
            
            <i class="icon icon-folder"></i>
            
            <span class="menu-title">分类</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-tags">
          <a href="/blog/tags">
            
            <i class="icon icon-tags"></i>
            
            <span class="menu-title">标签</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-repository">
          <a href="/blog/repository">
            
            <i class="icon icon-project"></i>
            
            <span class="menu-title">项目</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-links">
          <a href="/blog/links">
            
            <i class="icon icon-friendship"></i>
            
            <span class="menu-title">友链</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-about">
          <a href="/blog/about">
            
            <i class="icon icon-cup-fill"></i>
            
            <span class="menu-title">关于</span>
          </a>
        </li>
        
      </ul>
      
	
    <ul class="social-links">
    	
        <li><a href="https://github.com/jirryji" target="_blank" title="Github" data-toggle=tooltip data-placement=top><i class="icon icon-github"></i></a></li>
        
        <li><a href="https://weibo.com/7355950025" target="_blank" title="Weibo" data-toggle=tooltip data-placement=top><i class="icon icon-weibo"></i></a></li>
        
        <li><a href="/blog/atom.xml" target="_blank" title="Rss" data-toggle=tooltip data-placement=top><i class="icon icon-rss"></i></a></li>
        
    </ul>

    </nav>
  </div>
</header>

  
    <aside class="sidebar" itemscope itemtype="http://schema.org/WPSideBar">
  <div class="slimContent">
    
      <div class="widget">
    <h3 class="widget-title">公告</h3>
    <div class="widget-body">
        <div id="board">
            <div class="content">
                <p>欢迎交流与分享经验!</p>
            </div>
        </div>
    </div>
</div>

    
      
  <div class="widget">
    <h3 class="widget-title">分类</h3>
    <div class="widget-body">
      <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/blog/categories/docker/">docker</a><span class="category-list-count">4</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/elasticsearch/">elasticsearch</a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/java/">java</a><span class="category-list-count">9</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/php/">php</a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/">版本控制</a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/%E8%AF%AD%E6%B3%95/">语法</a><span class="category-list-count">1</span><ul class="category-list-child"><li class="category-list-item"><a class="category-list-link" href="/blog/categories/%E8%AF%AD%E6%B3%95/markdown-%E8%AF%AD%E6%B3%95/">markdown 语法</a><span class="category-list-count">1</span></li></ul></li></ul>
    </div>
  </div>


    
      
  <div class="widget">
    <h3 class="widget-title">标签</h3>
    <div class="widget-body">
      <ul class="tag-list" itemprop="keywords"><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/aop/" rel="tag">aop</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/bloom-filter/" rel="tag">bloom-filter</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/busybox/" rel="tag">busybox</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/docker/" rel="tag">docker</a><span class="tag-list-count">4</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/elasticsearch/" rel="tag">elasticsearch</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/es/" rel="tag">es</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/filter/" rel="tag">filter</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/git/" rel="tag">git</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/hashMap/" rel="tag">hashMap</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/idea/" rel="tag">idea</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/interceptor/" rel="tag">interceptor</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/iterator/" rel="tag">iterator</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/java/" rel="tag">java</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/localDateTime/" rel="tag">localDateTime</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/map/" rel="tag">map</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/markdown/" rel="tag">markdown</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/maven/" rel="tag">maven</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/redis/" rel="tag">redis</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/redis-lua%E8%84%9A%E6%9C%AC/" rel="tag">redis lua脚本</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/volumes/" rel="tag">volumes</a><span class="tag-list-count">1</span></li></ul>
    </div>
  </div>


    
      
  <div class="widget">
    <h3 class="widget-title">标签云</h3>
    <div class="widget-body tagcloud">
      <a href="/blog/tags/aop/" style="font-size: 13px;">aop</a> <a href="/blog/tags/bloom-filter/" style="font-size: 13px;">bloom-filter</a> <a href="/blog/tags/busybox/" style="font-size: 13px;">busybox</a> <a href="/blog/tags/docker/" style="font-size: 14px;">docker</a> <a href="/blog/tags/elasticsearch/" style="font-size: 13.67px;">elasticsearch</a> <a href="/blog/tags/es/" style="font-size: 13px;">es</a> <a href="/blog/tags/filter/" style="font-size: 13.33px;">filter</a> <a href="/blog/tags/git/" style="font-size: 13.33px;">git</a> <a href="/blog/tags/hashMap/" style="font-size: 13px;">hashMap</a> <a href="/blog/tags/idea/" style="font-size: 13px;">idea</a> <a href="/blog/tags/interceptor/" style="font-size: 13px;">interceptor</a> <a href="/blog/tags/iterator/" style="font-size: 13px;">iterator</a> <a href="/blog/tags/java/" style="font-size: 13.67px;">java</a> <a href="/blog/tags/localDateTime/" style="font-size: 13px;">localDateTime</a> <a href="/blog/tags/map/" style="font-size: 13px;">map</a> <a href="/blog/tags/markdown/" style="font-size: 13px;">markdown</a> <a href="/blog/tags/maven/" style="font-size: 13.67px;">maven</a> <a href="/blog/tags/redis/" style="font-size: 13px;">redis</a> <a href="/blog/tags/redis-lua%E8%84%9A%E6%9C%AC/" style="font-size: 13px;">redis lua脚本</a> <a href="/blog/tags/volumes/" style="font-size: 13px;">volumes</a>
    </div>
  </div>

    
      
  <div class="widget">
    <h3 class="widget-title">归档</h3>
    <div class="widget-body">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2020/01/">一月 2020</a><span class="archive-list-count">9</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2019/12/">十二月 2019</a><span class="archive-list-count">11</span></li></ul>
    </div>
  </div>


    
      
  <div class="widget">
    <h3 class="widget-title">最新文章</h3>
    <div class="widget-body">
      <ul class="recent-post-list list-unstyled no-thumbnail">
        
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="/blog/categories/java/">java</a>
              </p>
              <p class="item-title">
                <a href="/blog/2020/01/14/java/maven/mvn-private-repo/" class="title">Maven私服（Nexus）搭建</a>
              </p>
              <p class="item-date">
                <time datetime="2020-01-14T13:37:39.000Z" itemprop="datePublished">2020-01-14</time>
              </p>
            </div>
          </li>
          
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="/blog/categories/java/">java</a>
              </p>
              <p class="item-title">
                <a href="/blog/2020/01/09/java/java-idea-start-slow/" class="title">解决Idea启动Spring Boot很慢的问题</a>
              </p>
              <p class="item-date">
                <time datetime="2020-01-09T15:24:15.000Z" itemprop="datePublished">2020-01-09</time>
              </p>
            </div>
          </li>
          
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="/blog/categories/java/">java</a>
              </p>
              <p class="item-title">
                <a href="/blog/2020/01/09/java/java-springboot-filter-in-aop/" class="title">AOP（面向切面编程）、Filter（过虑器）、Interceptor（拦截器）</a>
              </p>
              <p class="item-date">
                <time datetime="2020-01-09T15:24:15.000Z" itemprop="datePublished">2020-01-09</time>
              </p>
            </div>
          </li>
          
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="/blog/categories/java/">java</a>
              </p>
              <p class="item-title">
                <a href="/blog/2020/01/09/java/java-req-resp/" class="title">HttpServletRequest 与 HttpServletResponse 的实现类</a>
              </p>
              <p class="item-date">
                <time datetime="2020-01-09T08:24:15.000Z" itemprop="datePublished">2020-01-09</time>
              </p>
            </div>
          </li>
          
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="/blog/categories/java/">java</a>
              </p>
              <p class="item-title">
                <a href="/blog/2020/01/09/java/java-springboot-filter/" class="title">Spring Boot 过滤器 Filter</a>
              </p>
              <p class="item-date">
                <time datetime="2020-01-09T08:24:15.000Z" itemprop="datePublished">2020-01-09</time>
              </p>
            </div>
          </li>
          
      </ul>
    </div>
  </div>
  

    
  </div>
</aside>

  
  
<aside class="sidebar sidebar-toc collapse" id="collapseToc" itemscope itemtype="http://schema.org/WPSideBar">
  <div class="slimContent">
    <nav id="toc" class="article-toc">
      <h3 class="toc-title">文章目录</h3>
      <ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#查看命令"><span class="toc-number">1.</span> <span class="toc-text">查看命令</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#查看-Docker-帮助"><span class="toc-number">1.1.</span> <span class="toc-text">查看 Docker 帮助</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#查看-Docker-版本"><span class="toc-number">1.2.</span> <span class="toc-text">查看 Docker 版本</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#查看-Docker-命令帮助"><span class="toc-number">1.3.</span> <span class="toc-text">查看 Docker 命令帮助</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#查看容器底层信息"><span class="toc-number">1.4.</span> <span class="toc-text">查看容器底层信息</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#镜像命令"><span class="toc-number">2.</span> <span class="toc-text">镜像命令</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#查看镜像"><span class="toc-number">2.1.</span> <span class="toc-text">查看镜像</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#搜索镜像"><span class="toc-number">2.2.</span> <span class="toc-text">搜索镜像</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#获取镜像"><span class="toc-number">2.3.</span> <span class="toc-text">获取镜像</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#删除镜像"><span class="toc-number">2.4.</span> <span class="toc-text">删除镜像</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#容器命令"><span class="toc-number">3.</span> <span class="toc-text">容器命令</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#查看容器"><span class="toc-number">3.1.</span> <span class="toc-text">查看容器</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#创建并运行容器"><span class="toc-number">3.2.</span> <span class="toc-text">创建并运行容器</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#启动容器"><span class="toc-number">3.3.</span> <span class="toc-text">启动容器</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#容器自启动"><span class="toc-number">3.4.</span> <span class="toc-text">容器自启动</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#停止容器"><span class="toc-number">3.5.</span> <span class="toc-text">停止容器</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#停止所有容器"><span class="toc-number">3.6.</span> <span class="toc-text">停止所有容器</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#重启容器"><span class="toc-number">3.7.</span> <span class="toc-text">重启容器</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#删除容器"><span class="toc-number">3.8.</span> <span class="toc-text">删除容器</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#清理已停止容器"><span class="toc-number">3.9.</span> <span class="toc-text">清理已停止容器</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#进入容器"><span class="toc-number">3.10.</span> <span class="toc-text">进入容器</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#退出容器"><span class="toc-number">3.11.</span> <span class="toc-text">退出容器</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#查看容器日志"><span class="toc-number">3.12.</span> <span class="toc-text">查看容器日志</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#查看容器进程"><span class="toc-number">3.13.</span> <span class="toc-text">查看容器进程</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#导出容器"><span class="toc-number">3.14.</span> <span class="toc-text">导出容器</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#导入容器"><span class="toc-number">3.15.</span> <span class="toc-text">导入容器</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#网络命令"><span class="toc-number">4.</span> <span class="toc-text">网络命令</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#默认网络"><span class="toc-number">4.1.</span> <span class="toc-text">默认网络</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#网络模式"><span class="toc-number">4.2.</span> <span class="toc-text">网络模式</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#查看网络"><span class="toc-number">4.3.</span> <span class="toc-text">查看网络</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#创建网络"><span class="toc-number">4.4.</span> <span class="toc-text">创建网络</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#参数说明"><span class="toc-number">4.4.0.1.</span> <span class="toc-text">参数说明</span></a></li></ol></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#删除网络"><span class="toc-number">4.5.</span> <span class="toc-text">删除网络</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#系统命令"><span class="toc-number">5.</span> <span class="toc-text">系统命令</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#查看容器资源"><span class="toc-number">5.1.</span> <span class="toc-text">查看容器资源</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#数据卷挂载"><span class="toc-number">5.2.</span> <span class="toc-text">数据卷挂载</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#查看所有数据卷"><span class="toc-number">5.2.1.</span> <span class="toc-text">查看所有数据卷</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#查看所有未使用的数据卷"><span class="toc-number">5.2.2.</span> <span class="toc-text">查看所有未使用的数据卷</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#查看数据卷详细信息"><span class="toc-number">5.2.3.</span> <span class="toc-text">查看数据卷详细信息</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#创建数据卷"><span class="toc-number">5.2.4.</span> <span class="toc-text">创建数据卷</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#删除数据卷"><span class="toc-number">5.2.5.</span> <span class="toc-text">删除数据卷</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#删除所有未使用数据卷"><span class="toc-number">5.2.6.</span> <span class="toc-text">删除所有未使用数据卷</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#文件拷贝"><span class="toc-number">5.3.</span> <span class="toc-text">文件拷贝</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#从容器拷贝到宿主机"><span class="toc-number">5.3.1.</span> <span class="toc-text">从容器拷贝到宿主机</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#从宿主机拷贝到容器"><span class="toc-number">5.3.2.</span> <span class="toc-text">从宿主机拷贝到容器</span></a></li></ol></li></ol></li></ol>
    </nav>
  </div>
</aside>

<main class="main" role="main">
  <div class="content">
  <article id="post-docker/docker-common" class="article article-type-post" itemscope itemtype="http://schema.org/BlogPosting">
    
    <div class="article-header">
      
        
  
    <h1 class="article-title" itemprop="name">
      Docker 常用命令
    </h1>
  

      
      <div class="article-meta">
        <span class="article-date">
    <i class="icon icon-calendar-check"></i>
	<a href="/blog/2019/12/25/docker/docker-common/" class="article-date">
	  <time datetime="2019-12-25T15:40:15.000Z" itemprop="datePublished">2019-12-25</time>
	</a>
</span>
        
  <span class="article-category">
    <i class="icon icon-folder"></i>
    <a class="article-category-link" href="/blog/categories/docker/">docker</a>
  </span>

        
  <span class="article-tag">
    <i class="icon icon-tags"></i>
	<a class="article-tag-link" href="/blog/tags/docker/" rel="tag">docker</a>
  </span>


        
	<span class="article-read hidden-xs">
	    <i class="icon icon-eye-fill" aria-hidden="true"></i>
	    <span id="busuanzi_container_page_pv">
			<span id="busuanzi_value_page_pv">0</span>
		</span>
	</span>


        <span class="post-comment"><i class="icon icon-comment"></i> <a href="/blog/2019/12/25/docker/docker-common/#comments" class="article-comment-link">评论</a></span>
        
	
	

      </div>
    </div>
    <div class="article-entry marked-body" itemprop="articleBody">
      
        <h1 id="查看命令"><a href="#查看命令" class="headerlink" title="查看命令"></a>查看命令</h1><h2 id="查看-Docker-帮助"><a href="#查看-Docker-帮助" class="headerlink" title="查看 Docker 帮助"></a>查看 Docker 帮助</h2><p><strong>命令：<code>docker</code> 或<code>docker --help</code></strong></p>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">[jirenyoudeMacBook-Pro:~ jirry]$ docker --<span class="built_in">help</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"></span></pre></td></tr><tr><td class="code"><pre><span class="line">Usage:	docker [OPTIONS] COMMAND</span></pre></td></tr><tr><td class="code"><pre><span class="line"></span></pre></td></tr><tr><td class="code"><pre><span class="line">A self-sufficient runtime <span class="keyword">for</span> containers</span></pre></td></tr><tr><td class="code"><pre><span class="line"></span></pre></td></tr><tr><td class="code"><pre><span class="line">Options:</span></pre></td></tr><tr><td class="code"><pre><span class="line">      --config string      Location of client config files (default <span class="string">"/Users/jirry/.docker"</span>)</span></pre></td></tr><tr><td class="code"><pre><span class="line">  -D, --debug              Enable debug mode</span></pre></td></tr><tr><td class="code"><pre><span class="line">  -H, --host list          Daemon socket(s) to connect to</span></pre></td></tr><tr><td class="code"><pre><span class="line">  -l, --<span class="built_in">log</span>-level string   Set the logging level (<span class="string">"debug"</span>|<span class="string">"info"</span>|<span class="string">"warn"</span>|<span class="string">"error"</span>|<span class="string">"fatal"</span>) (default <span class="string">"info"</span>)</span></pre></td></tr><tr><td class="code"><pre><span class="line">      --tls                Use TLS; implied by --tlsverify</span></pre></td></tr><tr><td class="code"><pre><span class="line">      --tlscacert string   Trust certs signed only by this CA (default <span class="string">"/Users/jirry/.docker/ca.pem"</span>)</span></pre></td></tr><tr><td class="code"><pre><span class="line">      --tlscert string     Path to TLS certificate file (default <span class="string">"/Users/jirry/.docker/cert.pem"</span>)</span></pre></td></tr><tr><td class="code"><pre><span class="line">      --tlskey string      Path to TLS key file (default <span class="string">"/Users/jirry/.docker/key.pem"</span>)</span></pre></td></tr><tr><td class="code"><pre><span class="line">      --tlsverify          Use TLS and verify the remote</span></pre></td></tr><tr><td class="code"><pre><span class="line">  -v, --version            Print version information and quit</span></pre></td></tr><tr><td class="code"><pre><span class="line"></span></pre></td></tr><tr><td class="code"><pre><span class="line">Management Commands:</span></pre></td></tr><tr><td class="code"><pre><span class="line">  builder     Manage builds</span></pre></td></tr><tr><td class="code"><pre><span class="line">  config      Manage Docker configs</span></pre></td></tr><tr><td class="code"><pre><span class="line">  container   Manage containers</span></pre></td></tr><tr><td class="code"><pre><span class="line">  image       Manage images</span></pre></td></tr><tr><td class="code"><pre><span class="line">  network     Manage networks</span></pre></td></tr><tr><td class="code"><pre><span class="line">  node        Manage Swarm nodes</span></pre></td></tr><tr><td class="code"><pre><span class="line">  plugin      Manage plugins</span></pre></td></tr><tr><td class="code"><pre><span class="line">  secret      Manage Docker secrets</span></pre></td></tr><tr><td class="code"><pre><span class="line">  service     Manage services</span></pre></td></tr><tr><td class="code"><pre><span class="line">  stack       Manage Docker stacks</span></pre></td></tr><tr><td class="code"><pre><span class="line">  swarm       Manage Swarm</span></pre></td></tr><tr><td class="code"><pre><span class="line">  system      Manage Docker</span></pre></td></tr><tr><td class="code"><pre><span class="line">  trust       Manage trust on Docker images</span></pre></td></tr><tr><td class="code"><pre><span class="line">  volume      Manage volumes</span></pre></td></tr><tr><td class="code"><pre><span class="line"></span></pre></td></tr><tr><td class="code"><pre><span class="line">Commands:</span></pre></td></tr><tr><td class="code"><pre><span class="line">  attach      Attach <span class="built_in">local</span> standard input, output, and error streams to a running container</span></pre></td></tr><tr><td class="code"><pre><span class="line">  build       Build an image from a Dockerfile</span></pre></td></tr><tr><td class="code"><pre><span class="line">  commit      Create a new image from a container<span class="string">'s changes</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="string">  cp          Copy files/folders between a container and the local filesystem</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="string">  create      Create a new container</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="string">  diff        Inspect changes to files or directories on a container'</span>s filesystem</span></pre></td></tr><tr><td class="code"><pre><span class="line">  events      Get real time events from the server</span></pre></td></tr><tr><td class="code"><pre><span class="line">  <span class="built_in">exec</span>        Run a <span class="built_in">command</span> <span class="keyword">in</span> a running container</span></pre></td></tr><tr><td class="code"><pre><span class="line">  <span class="built_in">export</span>      Export a container<span class="string">'s filesystem as a tar archive</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="string">  history     Show the history of an image</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="string">  images      List images</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="string">  import      Import the contents from a tarball to create a filesystem image</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="string">  info        Display system-wide information</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="string">  inspect     Return low-level information on Docker objects</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="string">  kill        Kill one or more running containers</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="string">  load        Load an image from a tar archive or STDIN</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="string">  login       Log in to a Docker registry</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="string">  logout      Log out from a Docker registry</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="string">  logs        Fetch the logs of a container</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="string">  pause       Pause all processes within one or more containers</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="string">  port        List port mappings or a specific mapping for the container</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="string">  ps          List containers</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="string">  pull        Pull an image or a repository from a registry</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="string">  push        Push an image or a repository to a registry</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="string">  rename      Rename a container</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="string">  restart     Restart one or more containers</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="string">  rm          Remove one or more containers</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="string">  rmi         Remove one or more images</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="string">  run         Run a command in a new container</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="string">  save        Save one or more images to a tar archive (streamed to STDOUT by default)</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="string">  search      Search the Docker Hub for images</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="string">  start       Start one or more stopped containers</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="string">  stats       Display a live stream of container(s) resource usage statistics</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="string">  stop        Stop one or more running containers</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="string">  tag         Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="string">  top         Display the running processes of a container</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="string">  unpause     Unpause all processes within one or more containers</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="string">  update      Update configuration of one or more containers</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="string">  version     Show the Docker version information</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="string">  wait        Block until one or more containers stop, then print their exit codes</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="string"></span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="string">Run '</span>docker COMMAND --<span class="built_in">help</span><span class="string">' for more information on a command.</span></span></pre></td></tr></table></figure>

<h2 id="查看-Docker-版本"><a href="#查看-Docker-版本" class="headerlink" title="查看 Docker 版本"></a>查看 Docker 版本</h2><p><strong>命令：<code>docker --version</code> 或 <code>docker version</code></strong></p>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">[jirenyoudeMacBook-Pro:~ jirry]$ docker --version</span></pre></td></tr><tr><td class="code"><pre><span class="line">Docker version 18.09.2, build 6247962</span></pre></td></tr></table></figure>

<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">[jirenyoudeMacBook-Pro:~ jirry]$ docker version</span></pre></td></tr><tr><td class="code"><pre><span class="line">Client: Docker Engine - Community</span></pre></td></tr><tr><td class="code"><pre><span class="line"> Version:           18.09.2</span></pre></td></tr><tr><td class="code"><pre><span class="line"> API version:       1.39</span></pre></td></tr><tr><td class="code"><pre><span class="line"> Go version:        go1.10.8</span></pre></td></tr><tr><td class="code"><pre><span class="line"> Git commit:        6247962</span></pre></td></tr><tr><td class="code"><pre><span class="line"> Built:             Sun Feb 10 04:12:39 2019</span></pre></td></tr><tr><td class="code"><pre><span class="line"> OS/Arch:           darwin/amd64</span></pre></td></tr><tr><td class="code"><pre><span class="line"> Experimental:      <span class="literal">false</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"></span></pre></td></tr><tr><td class="code"><pre><span class="line">Server: Docker Engine - Community</span></pre></td></tr><tr><td class="code"><pre><span class="line"> Engine:</span></pre></td></tr><tr><td class="code"><pre><span class="line">  Version:          18.09.2</span></pre></td></tr><tr><td class="code"><pre><span class="line">  API version:      1.39 (minimum version 1.12)</span></pre></td></tr><tr><td class="code"><pre><span class="line">  Go version:       go1.10.6</span></pre></td></tr><tr><td class="code"><pre><span class="line">  Git commit:       6247962</span></pre></td></tr><tr><td class="code"><pre><span class="line">  Built:            Sun Feb 10 04:13:06 2019</span></pre></td></tr><tr><td class="code"><pre><span class="line">  OS/Arch:          linux/amd64</span></pre></td></tr><tr><td class="code"><pre><span class="line">  Experimental:     <span class="literal">false</span></span></pre></td></tr></table></figure>

<h2 id="查看-Docker-命令帮助"><a href="#查看-Docker-命令帮助" class="headerlink" title="查看 Docker 命令帮助"></a>查看 Docker 命令帮助</h2><blockquote>
<p>可以使用 <code>docker [commond] --help</code> 查看命令更多使用方法</p>
</blockquote>
<p><strong>命令：<code>docker [COMMOND] --help</code></strong></p>
<ul>
<li>COMMOND：命令</li>
</ul>
<p>如：查看 stats 命令详细使用(docker stats 命令用来显示容器使用的系统资源)</p>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">[jirenyoudeMacBook-Pro:~ jirry]$ docker stats --<span class="built_in">help</span></span></pre></td></tr><tr><td class="code"><pre><span class="line">Usage:	docker stats [OPTIONS] [CONTAINER...]</span></pre></td></tr><tr><td class="code"><pre><span class="line">Display a live stream of container(s) resource usage statistics</span></pre></td></tr><tr><td class="code"><pre><span class="line">Options:</span></pre></td></tr><tr><td class="code"><pre><span class="line">  -a, --all             Show all containers (default shows just running)</span></pre></td></tr><tr><td class="code"><pre><span class="line">      --format string   Pretty-print images using a Go template</span></pre></td></tr><tr><td class="code"><pre><span class="line">      --no-stream       Disable streaming stats and only pull the first result</span></pre></td></tr><tr><td class="code"><pre><span class="line">      --no-trunc        Do not truncate output</span></pre></td></tr></table></figure>

<h2 id="查看容器底层信息"><a href="#查看容器底层信息" class="headerlink" title="查看容器底层信息"></a>查看容器底层信息</h2><blockquote>
<p>查看容器系统相关底层信息</p>
</blockquote>
<p><strong>命令：docker inspect [NAME|ID]</strong></p>
<ul>
<li>NAME：容器名称</li>
<li>ID：容器ID</li>
</ul>
<p>查看 MyCentOS 容器底层系统信息</p>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">[jirenyoudeMacBook-Pro:<span class="built_in">local</span> jirry]$ docker inspect MyCentOS</span></pre></td></tr><tr><td class="code"><pre><span class="line">[</span></pre></td></tr><tr><td class="code"><pre><span class="line">    &#123;</span></pre></td></tr><tr><td class="code"><pre><span class="line">        <span class="string">"Id"</span>: <span class="string">"e03121d8af5966a1918202ffdfa92d4e285d6ba76bed5a2e16f421493fe27919"</span>,</span></pre></td></tr><tr><td class="code"><pre><span class="line">        <span class="string">"Created"</span>: <span class="string">"2019-12-29T13:40:17.5184458Z"</span>,</span></pre></td></tr><tr><td class="code"><pre><span class="line">        <span class="string">"Path"</span>: <span class="string">"/bin/bash"</span>,</span></pre></td></tr><tr><td class="code"><pre><span class="line">        <span class="string">"Args"</span>: [],</span></pre></td></tr><tr><td class="code"><pre><span class="line">        <span class="string">"State"</span>: &#123;</span></pre></td></tr><tr><td class="code"><pre><span class="line">            <span class="string">"Status"</span>: <span class="string">"running"</span>,</span></pre></td></tr><tr><td class="code"><pre><span class="line">            <span class="string">"Running"</span>: <span class="literal">true</span>,</span></pre></td></tr><tr><td class="code"><pre><span class="line">            <span class="string">"Paused"</span>: <span class="literal">false</span>,</span></pre></td></tr><tr><td class="code"><pre><span class="line">            <span class="string">"Restarting"</span>: <span class="literal">false</span>,</span></pre></td></tr><tr><td class="code"><pre><span class="line">            <span class="string">"OOMKilled"</span>: <span class="literal">false</span>,</span></pre></td></tr><tr><td class="code"><pre><span class="line">            <span class="string">"Dead"</span>: <span class="literal">false</span>,</span></pre></td></tr><tr><td class="code"><pre><span class="line">            <span class="string">"Pid"</span>: 3552,</span></pre></td></tr><tr><td class="code"><pre><span class="line">            <span class="string">"ExitCode"</span>: 0,</span></pre></td></tr><tr><td class="code"><pre><span class="line">            <span class="string">"Error"</span>: <span class="string">""</span>,</span></pre></td></tr><tr><td class="code"><pre><span class="line">            <span class="string">"StartedAt"</span>: <span class="string">"2019-12-29T14:29:48.4907232Z"</span>,</span></pre></td></tr><tr><td class="code"><pre><span class="line">            <span class="string">"FinishedAt"</span>: <span class="string">"2019-12-29T14:29:47.0012324Z"</span></span></pre></td></tr><tr><td class="code"><pre><span class="line">        &#125;,</span></pre></td></tr><tr><td class="code"><pre><span class="line">        <span class="string">"Image"</span>: <span class="string">"sha256:0f3e07c0138fbe05abcb7a9cc7d63d9bd4c980c3f61fea5efa32e7c4217ef4da"</span>,</span></pre></td></tr><tr><td class="code"><pre><span class="line">        ...</span></pre></td></tr><tr><td class="code"><pre><span class="line">    &#125;</span></pre></td></tr><tr><td class="code"><pre><span class="line">    ...</span></pre></td></tr><tr><td class="code"><pre><span class="line">]</span></pre></td></tr></table></figure>

<h1 id="镜像命令"><a href="#镜像命令" class="headerlink" title="镜像命令"></a>镜像命令</h1><blockquote>
<p>当运行容器时，使用的镜像如果在本地中不存在，docker 就会自动从 docker 镜像仓库中下载，默认是从 Docker Hub 公共镜像源下载</p>
</blockquote>
<h2 id="查看镜像"><a href="#查看镜像" class="headerlink" title="查看镜像"></a>查看镜像</h2><blockquote>
<p>使用 <code>docker images</code> 查看本地镜像列表</p>
</blockquote>
<p><strong>命令：docker images [OPTIONS]</strong></p>
<ul>
<li>OPTIONS：参数选项</li>
</ul>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">[jirenyoudeMacBook-Pro:~ jirry]$ docker images -a</span></pre></td></tr><tr><td class="code"><pre><span class="line">REPOSITORY                      TAG                 IMAGE ID            CREATED             SIZE</span></pre></td></tr><tr><td class="code"><pre><span class="line">jirry/openresty                 1.13                24f48f1e3683        5 months ago        74.7MB</span></pre></td></tr></table></figure>

<p><strong>参数说明</strong></p>
<table>
<thead>
<tr>
<th>参数</th>
<th>描述</th>
</tr>
</thead>
<tbody><tr>
<td><code>-a</code>, <code>--all</code></td>
<td>查看所有镜像</td>
</tr>
</tbody></table>
<p><strong>输出内容</strong></p>
<table>
<thead>
<tr>
<th>字段</th>
<th>描述</th>
</tr>
</thead>
<tbody><tr>
<td>REPOSITORY</td>
<td>镜像仓库源</td>
</tr>
<tr>
<td>TAG</td>
<td>镜像标签版本</td>
</tr>
<tr>
<td>IMAGE ID</td>
<td>镜像ID</td>
</tr>
<tr>
<td>CREATED</td>
<td>创建时间</td>
</tr>
<tr>
<td>SIZE</td>
<td>镜像大小</td>
</tr>
</tbody></table>
<blockquote>
<p>同一仓库源可以有多个 TAG，代表这个仓库源的多个不同版本</p>
</blockquote>
<h2 id="搜索镜像"><a href="#搜索镜像" class="headerlink" title="搜索镜像"></a>搜索镜像</h2><p><strong>命令：<code>docker search [NAME]</code></strong></p>
<ul>
<li>NAME：镜像名称</li>
</ul>
<p>如：搜索 openresty 镜像</p>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">[jirenyoudeMacBook-Pro:~ jirry]$ docker search openresty</span></pre></td></tr><tr><td class="code"><pre><span class="line">NAME                            DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED</span></pre></td></tr><tr><td class="code"><pre><span class="line">openresty/openresty             OpenResty Official Docker Images - a dynamic…   264                                     [OK]</span></pre></td></tr><tr><td class="code"><pre><span class="line">ficusio/openresty               Minimalist OpenResty image                      23                                      [OK]</span></pre></td></tr><tr><td class="code"><pre><span class="line">3scale/openresty                Latest Openresty with redis and some handy p…   16                                      [OK]</span></pre></td></tr><tr><td class="code"><pre><span class="line">domecloud/openresty             OpenResty By DomeCloud - a dynamic web platf…   3                                       [OK]</span></pre></td></tr><tr><td class="code"><pre><span class="line">oondeo/openresty                Ngnix + openresty + naxsi                       2                                       [OK]</span></pre></td></tr><tr><td class="code"><pre><span class="line">pahud/openresty                 openresty with docker                           2                                       [OK]</span></pre></td></tr><tr><td class="code"><pre><span class="line">quiq/openresty                  Enhanced openresty image with pre-installed …   1                                       </span></pre></td></tr><tr><td class="code"><pre><span class="line">travix/openresty                Openresty-based sidecar to terminate ssl, au…   1                                       [OK]</span></pre></td></tr><tr><td class="code"><pre><span class="line">flixtech/openresty-oidc-proxy   An openresty based OpenID Connect Single Sig…   1                                       [OK]</span></pre></td></tr><tr><td class="code"><pre><span class="line">songshenzong/openresty          Docker Image packaging <span class="keyword">for</span> OpenResty            1                                       [OK]</span></pre></td></tr><tr><td class="code"><pre><span class="line">thesoul/openresty               OpenResty® is a full-fledged web platform.      1                                       </span></pre></td></tr><tr><td class="code"><pre><span class="line">myobplatform/openresty-oidc     Openresty                                       1                                       [OK]</span></pre></td></tr><tr><td class="code"><pre><span class="line">vikings/openresty               Openresty image base on centos 7                1                                       [OK]</span></pre></td></tr><tr><td class="code"><pre><span class="line">saksmlz/openresty-docker        Tiny image with nginx and openresty based on…   1                                       [OK]</span></pre></td></tr><tr><td class="code"><pre><span class="line">hasura/openresty                Openresty 1.9 debian image built nginx strea…   0                                       </span></pre></td></tr><tr><td class="code"><pre><span class="line">estafette/openresty-sidecar                                                     0                                       </span></pre></td></tr><tr><td class="code"><pre><span class="line">rmoriz/openresty_autossl        see https://github.com/rmoriz/docker_openres…   0                                       [OK]</span></pre></td></tr><tr><td class="code"><pre><span class="line">qzkc/openresty_base                                                             0                                       </span></pre></td></tr><tr><td class="code"><pre><span class="line">gotamedia/openresty-php         OpenResty and PHP-FPM with supervisord          0                                       </span></pre></td></tr><tr><td class="code"><pre><span class="line">spaziodati/openresty            Openresty docker image                          0                                       [OK]</span></pre></td></tr><tr><td class="code"><pre><span class="line">pcel/openresty                                                                  0                                       </span></pre></td></tr><tr><td class="code"><pre><span class="line">swaglive/openresty              Openresty                                       0                                       [OK]</span></pre></td></tr><tr><td class="code"><pre><span class="line">tansoft/openresty-php           php with openresty, yaf, swoole                 0                                       </span></pre></td></tr><tr><td class="code"><pre><span class="line">selim13/openresty-prometheus    An extended OpenResty image with the Prometh…   0                                       [OK]</span></pre></td></tr><tr><td class="code"><pre><span class="line">saagie/openresty-luarocks       OpenResty with some Lua modules installed       0                                       [OK]</span></pre></td></tr></table></figure>

<p><strong>输出内容</strong></p>
<table>
<thead>
<tr>
<th>字段</th>
<th>描述</th>
</tr>
</thead>
<tbody><tr>
<td>NAME</td>
<td>镜像仓库源的名称</td>
</tr>
<tr>
<td>DESCRIPTION</td>
<td>镜像描述</td>
</tr>
<tr>
<td>STARS</td>
<td>类似 Github 里面的 stars，表示点赞、喜欢的意思</td>
</tr>
<tr>
<td>OFFICIAL</td>
<td>是否 Docker 官方发布</td>
</tr>
<tr>
<td>AUTOMATED</td>
<td>是否自动构建</td>
</tr>
</tbody></table>
<h2 id="获取镜像"><a href="#获取镜像" class="headerlink" title="获取镜像"></a>获取镜像</h2><blockquote>
<p>当我们在本地主机上使用一个不存在的镜像时 Docker 就会自动下载这个镜像。如果我们想预先下载这个镜像，我们可以使用 <code>docker pull</code> 命令来下载它。</p>
</blockquote>
<p><strong>命令：docker pull [NAME:TAG]</strong></p>
<ul>
<li>NAME：镜像名称</li>
<li>TAG：镜像标签 (默认：lastest)</li>
</ul>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">[jirenyoudeMacBook-Pro:~ jirry]$ docker pull centos</span></pre></td></tr><tr><td class="code"><pre><span class="line">Using default tag: latest</span></pre></td></tr><tr><td class="code"><pre><span class="line">latest: Pulling from library/centos</span></pre></td></tr><tr><td class="code"><pre><span class="line">729ec3a6ada3: Pull complete </span></pre></td></tr><tr><td class="code"><pre><span class="line">Digest: sha256:f94c1d992c193b3dc09e297ffd54d8a4f1dc946c37cbeceb26d35ce1647f88d9</span></pre></td></tr><tr><td class="code"><pre><span class="line">Status: Downloaded newer image <span class="keyword">for</span> centos:latest</span></pre></td></tr></table></figure>

<h2 id="删除镜像"><a href="#删除镜像" class="headerlink" title="删除镜像"></a>删除镜像</h2><blockquote>
<p>删除一个或多个镜像</p>
</blockquote>
<p><strong>命令：<code>docker images rm [NAME|ID]</code> 或 <code>docker rmi [NAME|ID]</code></strong></p>
<ul>
<li>NAME： 镜像名称</li>
<li>ID：镜像ID</li>
</ul>
<h1 id="容器命令"><a href="#容器命令" class="headerlink" title="容器命令"></a>容器命令</h1><h2 id="查看容器"><a href="#查看容器" class="headerlink" title="查看容器"></a>查看容器</h2><blockquote>
<p>使用 <code>docker container ps</code> 或 <code>docker ps</code> 来查看正在运行或未运行的容器</p>
</blockquote>
<p><strong>命令：<code>docker container ps [OPTIONS]</code>或<code>docker ps [OPTIONS]</code></strong></p>
<ul>
<li>OPTIONS：参数选项</li>
</ul>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">[jirenyoudeMacBook-Pro:~ jirry]$ docker container ps</span></pre></td></tr><tr><td class="code"><pre><span class="line">CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES</span></pre></td></tr></table></figure>

<p><strong>参数说明</strong></p>
<table>
<thead>
<tr>
<th>参数</th>
<th>描述</th>
</tr>
</thead>
<tbody><tr>
<td><code>-a</code>,<code>--all</code></td>
<td>查看所有容器(包括：运行或停止的容器)</td>
</tr>
</tbody></table>
<p><strong>输出内容</strong></p>
<table>
<thead>
<tr>
<th>字段</th>
<th>描述</th>
</tr>
</thead>
<tbody><tr>
<td>CONTAINER ID</td>
<td>容器ID</td>
</tr>
<tr>
<td>IMAGE</td>
<td>容器运行镜像</td>
</tr>
<tr>
<td>COMMAND</td>
<td>容器运行命令</td>
</tr>
<tr>
<td>PORTS</td>
<td>容器端口监听及宿主机端口映射</td>
</tr>
</tbody></table>
<h2 id="创建并运行容器"><a href="#创建并运行容器" class="headerlink" title="创建并运行容器"></a>创建并运行容器</h2><p><strong>命令：<code>docker run [OPTIONS] [NAME:TAG] [CMD]</code></strong></p>
<ul>
<li>OPTIONS： 参数选项</li>
<li>NAME:TAG：镜像名称:镜像标签</li>
<li>CMD：运行命令</li>
</ul>
<p>创建并运行 myCentOS 容器</p>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">docker run -it --name myCentOS centos /bin/bash</span></pre></td></tr></table></figure>

<blockquote>
<p>进入容器后；可以输入 exit 退出容器</p>
</blockquote>
<p><strong>参数说明</strong></p>
<table>
<thead>
<tr>
<th>参数</th>
<th>描述</th>
</tr>
</thead>
<tbody><tr>
<td><code>-i</code>,<code>--interactive</code></td>
<td>交互式操作</td>
</tr>
<tr>
<td><code>-t</code>,<code>--terminal</code></td>
<td>终端</td>
</tr>
<tr>
<td><code>-d</code>,<code>--daemon</code></td>
<td>后台运行模式</td>
</tr>
<tr>
<td><code>-p</code>,<code>--port</code></td>
<td>主机端口与容器端口映射</td>
</tr>
<tr>
<td><code>-P</code></td>
<td>使用 -P 标记时，Docker 会随机映射一个 49000~49900 的端口到内部容器开放的网络端口</td>
</tr>
<tr>
<td><code>--name</code></td>
<td>容器名称</td>
</tr>
<tr>
<td><code>-v</code>,<code>--volumes</code></td>
<td>主机目录挂载容器目录 (<strong>容器目录不可以为相对路径</strong>)</td>
</tr>
<tr>
<td><code>--rm</code></td>
<td>退出或停止容器，自动销毁容器</td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
</tbody></table>
<h2 id="启动容器"><a href="#启动容器" class="headerlink" title="启动容器"></a>启动容器</h2><blockquote>
<p>启动一个已存在停止的容器</p>
</blockquote>
<p><strong>命令：<code>docker start [NAME|ID]</code> 或 <code>docker kill [NAME|ID]</code></strong></p>
<ul>
<li>NAME：容器名称</li>
<li>ID：容器ID</li>
</ul>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">[jirenyoudeMacBook-Pro:~ jirry]$ docker start myCentOS</span></pre></td></tr><tr><td class="code"><pre><span class="line">myCentOS</span></pre></td></tr></table></figure>

<h2 id="容器自启动"><a href="#容器自启动" class="headerlink" title="容器自启动"></a>容器自启动</h2><blockquote>
<p>在运行容器时，指定 <code>--restart</code>参数自启动策略，Docker容器的重启策略是面向生产环境的一个启动策略，在开发过程中可以忽略该策略。</p>
</blockquote>
<p><strong>容器重启策略</strong></p>
<ul>
<li>no：默认策略，在容器退出时不重启容器</li>
<li>on-failure：在容器非正常退出时（退出状态非0），才会重启容器</li>
<li>on-failure:3：在容器非正常退出时重启容器，最多重启3次</li>
<li>always：在容器退出时总是重启容器</li>
<li>unless-stopped：在容器退出时总是重启容器，但是不考虑在Docker守护进程启动时就已经停止了的容器unless</li>
<li>stopped：在容器退出时总是重启容器，但是不考虑在Docker守护进程启动时就已经停止了的容器</li>
</ul>
<p><strong>容器退出状态码</strong></p>
<ul>
<li>0：表示正常退出</li>
<li>非0：表示异常退出（退出状态码采用chroot标准）</li>
<li>125：Docker守护进程本身的错误</li>
<li>126：容器启动后，要执行的默认命令无法调用</li>
<li>127：容器启动后，要执行的默认命令不存在</li>
</ul>
<p><strong>运行并自启动 MyCentOS 容器，运行容器时增加 <code>--restart=always</code></strong></p>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">[jirenyoudeMacBook-Pro:~ jirry]$ docker run -itd --restart=always --name MyCentOS centos /bin/bash</span></pre></td></tr></table></figure>

<blockquote>
<p>如果在运行容器时，未指定重启策略，可以使用<code>docker container update</code>修改容器重启策略</p>
</blockquote>
<p><strong>命令：<code>docker container update --restart=always [NAME|ID]</code></strong></p>
<ul>
<li>NAME：容器名称</li>
<li>ID：容器ID</li>
</ul>
<h2 id="停止容器"><a href="#停止容器" class="headerlink" title="停止容器"></a>停止容器</h2><blockquote>
<p>停止正在运行的容器，有两种方式停止容器</p>
<ol>
<li>优雅停止容器<code>docker stop</code>等待容器结束任务后停止容器</li>
<li>强制停止容器<code>docker kill</code>直接退出杀掉容器进程，不等待容器结束任务</li>
</ol>
</blockquote>
<p><strong>命令：<code>docker stop [NAME|ID]</code></strong></p>
<ul>
<li>NAME：容器名称</li>
<li>ID：容器ID</li>
</ul>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">[jirenyoudeMacBook-Pro:~ jirry]$ docker stop myCentOS</span></pre></td></tr><tr><td class="code"><pre><span class="line">myCentOS</span></pre></td></tr></table></figure>

<h2 id="停止所有容器"><a href="#停止所有容器" class="headerlink" title="停止所有容器"></a>停止所有容器</h2><blockquote>
<p>停止所有容器docker没有提供直接的命令，需要查出所有容器ID，然后批量停止容器</p>
</blockquote>
<p><strong>命令：<code>docker stop $(docker ps -a -q)</code></strong></p>
<ul>
<li><code>$(docker ps -a -q)</code> ：查出所有容器ID，-q：打印容器ID</li>
</ul>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">[jirenyoudeMacBook-Pro:~ jirry]$ docker stop $(docker ps -a -q)</span></pre></td></tr></table></figure>



<h2 id="重启容器"><a href="#重启容器" class="headerlink" title="重启容器"></a>重启容器</h2><p><strong>命令：<code>docker restart [NAME|ID]</code></strong></p>
<ul>
<li>NAME：容器名称</li>
<li>ID：容器ID</li>
</ul>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">[jirenyoudeMacBook-Pro:~ jirry]$ docker restart MyCentOS</span></pre></td></tr><tr><td class="code"><pre><span class="line">MyCentOS</span></pre></td></tr></table></figure>

<h2 id="删除容器"><a href="#删除容器" class="headerlink" title="删除容器"></a>删除容器</h2><blockquote>
<p>删除已创建的容器</p>
</blockquote>
<p><strong>命令：<code>docker rm [OPTIONS] [NAME|ID]</code></strong></p>
<ul>
<li>OPTIONS：参数选项</li>
<li>NAME：容器名称</li>
<li>ID：容器ID</li>
</ul>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">[jirenyoudeMacBook-Pro:~ jirry]$ docker rm -f myCentOS</span></pre></td></tr><tr><td class="code"><pre><span class="line">myCentOS</span></pre></td></tr></table></figure>

<p><strong>参数说明</strong></p>
<table>
<thead>
<tr>
<th>参数</th>
<th>描述</th>
</tr>
</thead>
<tbody><tr>
<td><code>-f</code>,<code>--force</code></td>
<td>通过信号强制移除运行中的容器</td>
</tr>
<tr>
<td><code>-l</code>,<code>--link</code></td>
<td>移除容器之间的链接</td>
</tr>
<tr>
<td><code>-v</code>,<code>--volumes</code></td>
<td>删除与关联的挂载目录</td>
</tr>
</tbody></table>
<h2 id="清理已停止容器"><a href="#清理已停止容器" class="headerlink" title="清理已停止容器"></a>清理已停止容器</h2><blockquote>
<p>清理掉所有处于终止状态的容器</p>
</blockquote>
<p><strong>命令：<code>docker container prune</code></strong></p>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">[jirenyoudeMacBook-Pro:~ jirry]$ docker container prune</span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="comment"># 警告！这将删除所有停止的容器。</span></span></pre></td></tr><tr><td class="code"><pre><span class="line">WARNING! This will remove all stopped containers.</span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="comment"># 确定要继续吗？[是/否]</span></span></pre></td></tr><tr><td class="code"><pre><span class="line">Are you sure you want to <span class="built_in">continue</span>? [y/N]</span></pre></td></tr></table></figure>



<h2 id="进入容器"><a href="#进入容器" class="headerlink" title="进入容器"></a>进入容器</h2><blockquote>
<p>在使用 <strong>-d</strong> 参数时，容器启动后会进入后台。此时想要进入容器，可以通过以下两种命令进入一个正在运行的后台容器</p>
</blockquote>
<p><strong>[方式一]命令：<code>docker attach [NAME|ID]</code></strong></p>
<ul>
<li>NAME：容器名称</li>
<li>ID：容器ID</li>
</ul>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">[jirenyoudeMacBook-Pro:~ jirry]$ docker attach MyCentOS</span></pre></td></tr></table></figure>

<blockquote>
<p>注：这种方式进入容器，使用 <code>exit</code>退出后，容器运行状态也会随着停止，推荐使用第二种方式进入容器</p>
</blockquote>
<p><strong>[方式二]命令：docker exec [OPTIONS] [NAME|ID] [CMD]</strong></p>
<ul>
<li>OPTIONS：参数选项</li>
<li>NAME：容器名称</li>
<li>ID：容器ID</li>
<li>CMD：运行命令</li>
</ul>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">[jirenyoudeMacBook-Pro:~ jirry]$ docker <span class="built_in">exec</span> -it MyCentOS /bin/bash</span></pre></td></tr></table></figure>

<blockquote>
<p>这种方式进入容器，退出容器后，不会停止容器运行状态</p>
</blockquote>
<p><strong>参数说明</strong></p>
<table>
<thead>
<tr>
<th>参数</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td><code>-i</code>,<code>—interactive</code></td>
<td>交互式操作</td>
</tr>
<tr>
<td><code>-t</code>,<code>--terminal</code></td>
<td>终端</td>
</tr>
</tbody></table>
<h2 id="退出容器"><a href="#退出容器" class="headerlink" title="退出容器"></a>退出容器</h2><p><strong>命令：<code>exit</code></strong></p>
<p>进入 MyCentOS 容器，退出容器</p>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">[jirenyoudeMacBook-Pro:~ jirry]$ docker <span class="built_in">exec</span> -it MyCentOS /bin/bash</span></pre></td></tr><tr><td class="code"><pre><span class="line">[root@e03121d8af59 /]<span class="comment"># pwd</span></span></pre></td></tr><tr><td class="code"><pre><span class="line">/</span></pre></td></tr><tr><td class="code"><pre><span class="line">[root@e03121d8af59 /]<span class="comment"># exit</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="built_in">exit</span></span></pre></td></tr></table></figure>

<h2 id="查看容器日志"><a href="#查看容器日志" class="headerlink" title="查看容器日志"></a>查看容器日志</h2><blockquote>
<p>查看容器内部标准输出</p>
</blockquote>
<p><strong>命令：<code>docker logs [OPTIONS] [NAME|ID]</code></strong></p>
<ul>
<li>OPTIONS：参数选项</li>
<li>NAME：容器名称</li>
<li>ID：容器ID</li>
</ul>
<p>查看 MyCentOS 容器日志</p>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">[jirenyoudeMacBook-Pro:~ jirry]$ docker logs -f MyCentOS</span></pre></td></tr></table></figure>

<p><strong>参数说明</strong></p>
<table>
<thead>
<tr>
<th>参数</th>
<th>描述</th>
</tr>
</thead>
<tbody><tr>
<td><code>-f</code></td>
<td>同 <strong>tail -f</strong> 命令，实时监听日志</td>
</tr>
</tbody></table>
<h2 id="查看容器进程"><a href="#查看容器进程" class="headerlink" title="查看容器进程"></a>查看容器进程</h2><blockquote>
<p>可以使用 docker top 来查看容器内部运行的进程</p>
</blockquote>
<p><strong>命令：<code>docker top [NAME|ID]</code></strong></p>
<ul>
<li>NAME：容器名称</li>
<li>ID：容器ID</li>
</ul>
<p>查看 MyCentOS 容器进程</p>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">[jirenyoudeMacBook-Pro:~ jirry]$ docker top MyCentOS</span></pre></td></tr><tr><td class="code"><pre><span class="line">PID                 USER                TIME                COMMAND</span></pre></td></tr><tr><td class="code"><pre><span class="line">3552                root                0:00                /bin/bash</span></pre></td></tr></table></figure>

<h2 id="导出容器"><a href="#导出容器" class="headerlink" title="导出容器"></a>导出容器</h2><p><strong>命令：<code>docker export [NAME|ID] &gt; [PATH]</code></strong></p>
<ul>
<li>NAME：容器名称</li>
<li>ID：容器ID</li>
<li>PATH：导出容器快照文件</li>
</ul>
<p>将 MyCentOS 容器导出快照到本地 /data/MyCentOS.tar.gz </p>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">[jirenyoudeMacBook-Pro:~ jirry]$ docker <span class="built_in">export</span> MyCentOS &gt; /data/MyCentOS.tar.gz</span></pre></td></tr></table></figure>

<h2 id="导入容器"><a href="#导入容器" class="headerlink" title="导入容器"></a>导入容器</h2><p><strong>命令：<code>docker import [PATH] [NAME:TAG]</code></strong></p>
<ul>
<li>PATH：导入容器快照文件</li>
<li>NAME：镜像名</li>
<li>TAG：镜像标签</li>
</ul>
<p>将本地容器快照 /data/MyCentOS.tar.gz 导入镜像名为 jirry/mycentos:v1.0</p>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">[jirenyoudeMacBook-Pro:~ jirry]$ docker import /data/MyCentOS.tar.gz jirry/mycentos:v1.0</span></pre></td></tr></table></figure>

<blockquote>
<p>注：镜像名必须全部小写</p>
</blockquote>
<h1 id="网络命令"><a href="#网络命令" class="headerlink" title="网络命令"></a>网络命令</h1><blockquote>
<p>通常网络一般用于容器之间通讯连接， Docker 提供了 5 种网络驱动模式，要构建具有安全的一致行为的 Web 应用程序，可以使用 Docker 网络特性。根据定义网络，为容器实现完全隔离。</p>
<p>所有 Docker 安装后都存在的 docker0 网络，除非使用 <strong>docker run –network=</strong> 选项另行指定，否则 Docker 守护进程默认情况下会将容器连接到 docker0 这个网络</p>
</blockquote>
<h2 id="默认网络"><a href="#默认网络" class="headerlink" title="默认网络"></a>默认网络</h2><blockquote>
<p>安装 Docker 时，默认会自动创建 3 个网络，分别为：bridge、host、none，可以通过命令<code>docker network ls</code>查看所有网络</p>
<p>运行一个容器时，可以使用 <strong><code>--network</code></strong> 参数指定在哪种网络模式下运行该容器</p>
</blockquote>
<p>参考资料：<a href="https://www.cnkirito.moe/docker-network-bridge/" target="_blank" rel="noopener" title="Docker Network—Bridge 模式">Docker Network—Bridge 模式</a></p>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">[jirenyoudeMacBook-Pro:config jirry]$ docker network ls</span></pre></td></tr><tr><td class="code"><pre><span class="line">NETWORK ID          NAME                          DRIVER              SCOPE</span></pre></td></tr><tr><td class="code"><pre><span class="line">aa65a578400f        bridge                        bridge              <span class="built_in">local</span></span></pre></td></tr><tr><td class="code"><pre><span class="line">32f4054e8429        host                          host                <span class="built_in">local</span></span></pre></td></tr><tr><td class="code"><pre><span class="line">503c3adf1517        none                          null                <span class="built_in">local</span></span></pre></td></tr></table></figure>



<h2 id="网络模式"><a href="#网络模式" class="headerlink" title="网络模式"></a>网络模式</h2><table>
<thead>
<tr>
<th>模式</th>
<th>描述</th>
</tr>
</thead>
<tbody><tr>
<td>bridge</td>
<td>默认的网络驱动模式。如果不指定驱动程序，bridge 便会作为默认的网络驱动模式。当应用程序运行在需要通信的独立容器 (standalone containers) 中时，通常会选择 bridge 模式</td>
</tr>
<tr>
<td>host</td>
<td>移除容器和 Docker 宿主机之间的网络隔离，并直接使用主机的网络。host 模式仅适用于 Docker 17.06+</td>
</tr>
<tr>
<td>overlay</td>
<td>overlay 网络将多个 Docker 守护进程连接在一起，并使集群服务能够相互通信。您还可以使用 overlay 网络来实现 swarm 集群和独立容器之间的通信，或者不同 Docker 守护进程上的两个独立容器之间的通信。该策略实现了在这些容器之间进行操作系统级别路由的需求</td>
</tr>
<tr>
<td>macvlan</td>
<td>macvlan 网络允许为容器分配 MAC 地址，使其显示为网络上的物理设备。 Docker 守护进程通过其 MAC 地址将流量路由到容器。对于希望直连到物理网络的传统应用程序而言，使用 macvlan 模式一般是最佳选择，而不应该通过 Docker 宿主机的网络进行路由</td>
</tr>
<tr>
<td>none</td>
<td>对于此容器，禁用所有联网。通常与自定义网络驱动程序一起使用。none 模式不适用于集群服务</td>
</tr>
</tbody></table>
<h2 id="查看网络"><a href="#查看网络" class="headerlink" title="查看网络"></a>查看网络</h2><p><strong>命令：<code>docker network ls</code></strong></p>
<h2 id="创建网络"><a href="#创建网络" class="headerlink" title="创建网络"></a>创建网络</h2><p><strong>命令：<code>docker network create [OPTIONS] [MODEL] [NETWORK_NAME]</code></strong></p>
<ul>
<li>OPTIONS：参数选项</li>
<li>MODEL：网络模式</li>
<li>NETWORK_NAME：网络名称</li>
</ul>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">[jirenyoudeMacBook-Pro:config jirry]$ docker network create -d bridge network-1</span></pre></td></tr><tr><td class="code"><pre><span class="line">4d7cb1b46f2f94577dfa8529c36d680bc3ae3a38e19fd4c40a48da14a893302f</span></pre></td></tr></table></figure>

<h4 id="参数说明"><a href="#参数说明" class="headerlink" title="参数说明"></a>参数说明</h4><table>
<thead>
<tr>
<th>参数</th>
<th>描述</th>
</tr>
</thead>
<tbody><tr>
<td><code>-d</code></td>
<td>指定 Docker 网络模式，bridge、overlay 等</td>
</tr>
</tbody></table>
<h2 id="删除网络"><a href="#删除网络" class="headerlink" title="删除网络"></a>删除网络</h2><p><strong>命令：<code>docker network rm [NETWORK_NAME]</code></strong></p>
<ul>
<li>NETWORK_NAME：网络名称</li>
</ul>
<h1 id="系统命令"><a href="#系统命令" class="headerlink" title="系统命令"></a>系统命令</h1><h2 id="查看容器资源"><a href="#查看容器资源" class="headerlink" title="查看容器资源"></a>查看容器资源</h2><blockquote>
<p>docker stats 命令用来显示容器使用的系统资源，默认情况下，stats 命令会每隔 1 秒钟刷新一次输出的内容直到你按下 ctrl + c。下面是输出的主要内容：</p>
</blockquote>
<p><strong>命令：<code>docker stats [OPTIONS] [NAME|ID,...]</code></strong></p>
<ul>
<li>OPTIONS：参数选项</li>
<li>IMAGE：镜像名称</li>
<li>ID：镜像ID</li>
</ul>
<p><strong>命令参数</strong></p>
<table>
<thead>
<tr>
<th>参数</th>
<th>作用</th>
<th>描述</th>
</tr>
</thead>
<tbody><tr>
<td><code>--no-stream</code></td>
<td>返回当前容器状态</td>
<td>如果不想持续的监控容器使用资源的情况，可以通过 –no-stream 选项只输出当前的状态</td>
</tr>
<tr>
<td><code>[NAME]</code>或 <code>[ID]</code></td>
<td>输出指定的容器状态</td>
<td>name 容器名称 或 id 容器ID (注意：多个容器的名称或者是 ID 之间需要用空格进行分割)</td>
</tr>
</tbody></table>
<p><strong>输出内容</strong></p>
<table>
<thead>
<tr>
<th>字段</th>
<th>描述</th>
</tr>
</thead>
<tbody><tr>
<td>CONTAINER ID</td>
<td>容器的 ID (以短格式显示)</td>
</tr>
<tr>
<td>NAME</td>
<td>容器名称</td>
</tr>
<tr>
<td>CPU %</td>
<td>CPU 的使用情况</td>
</tr>
<tr>
<td>MEM USAGE / LIMIT</td>
<td>当前使用的内存和最大可以使用的内存</td>
</tr>
<tr>
<td>MEM %</td>
<td>以百分比的形式显示内存使用情况</td>
</tr>
<tr>
<td>NET I/O</td>
<td>网络 I/O 数据</td>
</tr>
<tr>
<td>BLOCK I/O</td>
<td>磁盘 I/O 数据</td>
</tr>
<tr>
<td>PIDS</td>
<td>PID 号</td>
</tr>
</tbody></table>
<h2 id="数据卷挂载"><a href="#数据卷挂载" class="headerlink" title="数据卷挂载"></a>数据卷挂载</h2><blockquote>
<p>Docker Volume能让容器从宿主主机中读取文件或持久化数据到宿主主机内，让容器与容器产生的数据分离开来。你可以简单地把它理解为linux服务器上的挂载点。一个容器可以挂载多个不同的目录。Volume的生命周期是独立于容器的生命周期之外的，即使容器删除了，volume也会被保留下来，Docker也不会因为这个volume没有被容器使用而回收。在容器中，添加或修改这个文件夹里的文件也不会影响容器的联合文件系统。</p>
</blockquote>
<p><strong>背景</strong></p>
<blockquote>
<p>数据卷不使用分层文件系统，这对经常读取和写入的数据很有利。在开发过程中，你可以把代码目录挂载到容器中，这样，如果你更改代码，容器会实时地得到文件修改的反馈。容器中的挂载点必须是绝对路径，不支持相对路径。宿主机上的地址可以是一个绝对路径，也可以是一个数据卷名（如果数据卷不存在，docker会自动创建数据卷）。</p>
<p>注意：不要在Dockerfile中指定挂载一个host主机的目录。不够灵活，因为在别的主机上不一定有这样一个目录。</p>
</blockquote>
<p>参考资料：<a href="https://loocode.com/post/10105" target="_blank" rel="noopener" title="Docker Volume入门用法详解">Docker Volume入门用法详解</a></p>
<p><strong>帮助命令：<code>docker volume --help</code></strong></p>
<table>
<thead>
<tr>
<th>命令</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td><code>create</code></td>
<td>Create a volume<br/>创建一个数据卷</td>
</tr>
<tr>
<td><code>inspect</code></td>
<td>Display detailed information on one or more volumes<br/>打印一个或多个数据卷的详细信息</td>
</tr>
<tr>
<td><code>ls</code></td>
<td>List volumes<br/>列出所有数据卷</td>
</tr>
<tr>
<td><code>prune</code></td>
<td>Remove all unused local volumes<br/>删除所有未使用的数据卷</td>
</tr>
<tr>
<td><code>rm</code></td>
<td>Remove one or more volumes<br>删除一个或多个数据卷</td>
</tr>
</tbody></table>
<h3 id="查看所有数据卷"><a href="#查看所有数据卷" class="headerlink" title="查看所有数据卷"></a>查看所有数据卷</h3><p><strong>命令：<code>docker volume ls</code></strong></p>
<h3 id="查看所有未使用的数据卷"><a href="#查看所有未使用的数据卷" class="headerlink" title="查看所有未使用的数据卷"></a>查看所有未使用的数据卷</h3><p><strong>命令：<code>docker volume ls -f dangling=true</code></strong></p>
<h3 id="查看数据卷详细信息"><a href="#查看数据卷详细信息" class="headerlink" title="查看数据卷详细信息"></a>查看数据卷详细信息</h3><p><strong>命令：<code>docker inspect [VOLUME_NAME]</code></strong></p>
<ul>
<li>VOLUME_NAME：数据卷名称</li>
</ul>
<h3 id="创建数据卷"><a href="#创建数据卷" class="headerlink" title="创建数据卷"></a>创建数据卷</h3><p><strong>命令：<code>docker volume create [VOLUME_NAME]</code></strong></p>
<ul>
<li>VOLUME_NAME：数据卷名称</li>
</ul>
<h3 id="删除数据卷"><a href="#删除数据卷" class="headerlink" title="删除数据卷"></a>删除数据卷</h3><p><strong>命令：<code>docker volume rm [VOLUME_NAME]</code></strong></p>
<ul>
<li>VOLUME_NAME：数据卷名称</li>
</ul>
<h3 id="删除所有未使用数据卷"><a href="#删除所有未使用数据卷" class="headerlink" title="删除所有未使用数据卷"></a>删除所有未使用数据卷</h3><p><strong>命令：<code>docker volume prune</code></strong></p>
<h2 id="文件拷贝"><a href="#文件拷贝" class="headerlink" title="文件拷贝"></a>文件拷贝</h2><blockquote>
<p>从容器里面拷文件或文件夹到宿主机，或者从宿主机拷贝文件或文件夹到容器中，在宿主机里面执行以下命令</p>
</blockquote>
<h3 id="从容器拷贝到宿主机"><a href="#从容器拷贝到宿主机" class="headerlink" title="从容器拷贝到宿主机"></a>从容器拷贝到宿主机</h3><p><strong>命令：<code>docker cp [CONTAINER:/CONTAINER_PATH] HOST_PATH</code></strong></p>
<ul>
<li><p>CONTAINER：容器名称或ID</p>
</li>
<li><p>CONTAINER_PATH：容器文件或文件夹路径</p>
</li>
<li><p>HOST_PATH：宿主机文件或文件夹路径</p>
<p>示例： 从容器 MyCentOS 中拷贝 /home/test.txt 到宿主机 /home/test.txt</p>
</li>
</ul>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">docker cp MyCentOS:/home/test.txt /home/test.txt</span></pre></td></tr></table></figure>



<h3 id="从宿主机拷贝到容器"><a href="#从宿主机拷贝到容器" class="headerlink" title="从宿主机拷贝到容器"></a>从宿主机拷贝到容器</h3><p><strong>命令：<code>docker cp HOST_PATH [CONTAINER:/CONTAINER_PATH]</code></strong></p>
<ul>
<li>CONTAINER：容器名称或ID</li>
<li>HOST_PATH：宿主机文件或文件夹路径</li>
<li>CONTAINER_PATH：容器文件或文件夹路径</li>
</ul>
<p>示例： 从宿主机拷贝 /home/test.txt 到容器 MyCentOS 中</p>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">docker cp /home/test.txt MyCentOS:/home/test.txt</span></pre></td></tr></table></figure>


      
    </div>
    <div class="article-footer">
      <blockquote class="mt-2x">
  <ul class="post-copyright list-unstyled">
    
    <li class="post-copyright-link hidden-xs">
      <strong>本文链接：</strong>
      <a href="http://jirenyou.gitee.io/blog/2019/12/25/docker/docker-common/" title="Docker 常用命令" target="_blank" rel="external">http://jirenyou.gitee.io/blog/2019/12/25/docker/docker-common/</a>
    </li>
    
    <li class="post-copyright-license">
      <strong>版权声明： </strong> 本博客所有文章除特别声明外，均采用 <a href="http://creativecommons.org/licenses/by/4.0/deed.zh" target="_blank" rel="external">CC BY 4.0 CN协议</a> 许可协议。转载请注明出处！
    </li>
  </ul>
</blockquote>


<div class="panel panel-default panel-badger">
  <div class="panel-body">
    <figure class="media">
      <div class="media-left">
        <a href="https://jirenyou.gitee.io/blog" target="_blank" class="img-burn thumb-sm visible-lg">
          <img src="/blog/images/avatar.jpg" class="img-rounded w-full" alt="">
        </a>
      </div>
      <div class="media-body">
        <h3 class="media-heading"><a href="https://jirenyou.gitee.io/blog" target="_blank"><span class="text-dark">Jirry</span><small class="ml-1x">Back end development Architecture</small></a></h3>
        <div>后端开发攻城狮，热爱互联网技术，爱学习，勤思考！</div>
      </div>
    </figure>
  </div>
</div>


    </div>
  </article>
  
    
  <section id="comments">
  	
      <div id="vcomments"></div>
    
  </section>


  
</div>

  <nav class="bar bar-footer clearfix" data-stick-bottom>
  <div class="bar-inner">
  
  <ul class="pager pull-left">
    
    <li class="prev">
      <a href="/blog/2019/12/25/docker/docker-tools-busybox/" title="BusyBox - Linux 系统瑞士军刀"><i class="icon icon-angle-left" aria-hidden="true"></i><span>&nbsp;&nbsp;上一篇</span></a>
    </li>
    
    
    <li class="next">
      <a href="/blog/2019/12/24/php/php-bloom-filter/" title="布隆过滤器(Bloom-filter)防Redis缓存穿透应用(PHP示例)"><span>下一篇&nbsp;&nbsp;</span><i class="icon icon-angle-right" aria-hidden="true"></i></a>
    </li>
    
    
    <li class="toggle-toc">
      <a class="toggle-btn collapsed" data-toggle="collapse" href="#collapseToc" aria-expanded="false" title="文章目录" role="button">
        <span>[&nbsp;</span><span>文章目录</span>
        <i class="text-collapsed icon icon-anchor"></i>
        <i class="text-in icon icon-close"></i>
        <span>]</span>
      </a>
    </li>
    
  </ul>
  
  
  <!-- Button trigger modal -->
  <button type="button" class="btn btn-fancy btn-donate pop-onhover bg-gradient-warning" data-toggle="modal" data-target="#donateModal"><span>赏</span></button>
  <!-- <div class="wave-icon wave-icon-danger btn-donate" data-toggle="modal" data-target="#donateModal">
    <div class="wave-circle"><span class="icon"><i class="icon icon-bill"></i></span></div>
  </div> -->
  
  
  <div class="bar-right">
    
    <div class="share-component" data-sites="weibo,qq,wechat,facebook,twitter" data-mobile-sites="weibo,qq,qzone"></div>
    
  </div>
  </div>
</nav>
  
<!-- Modal -->
<div class="modal modal-center modal-small modal-xs-full fade" id="donateModal" tabindex="-1" role="dialog">
  <div class="modal-dialog" role="document">
    <div class="modal-content donate">
      <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
      <div class="modal-body">
        <div class="donate-box">
          <div class="donate-head">
            <p>感谢您的支持，我会继续努力的!</p>
          </div>
          <div class="tab-content">
            <div role="tabpanel" class="tab-pane fade active in" id="alipay">
              <div class="donate-payimg">
                <img src="/blog/images/donate/alipay.jpeg" alt="扫码支持" title="扫一扫" />
              </div>
              <p class="text-muted mv">扫码打赏，你说多少就多少</p>
              <p class="text-grey">打开支付宝扫一扫，即可进行扫码打赏哦</p>
            </div>
            <div role="tabpanel" class="tab-pane fade" id="wechatpay">
              <div class="donate-payimg">
                <img src="/blog/images/donate/wechat.jpeg" alt="扫码支持" title="扫一扫" />
              </div>
              <p class="text-muted mv">扫码打赏，你说多少就多少</p>
              <p class="text-grey">打开微信扫一扫，即可进行扫码打赏哦</p>
            </div>
          </div>
          <div class="donate-footer">
            <ul class="nav nav-tabs nav-justified" role="tablist">
              <li role="presentation" class="active">
                <a href="#alipay" id="alipay-tab" role="tab" data-toggle="tab" aria-controls="alipay" aria-expanded="true"><i class="icon icon-alipay"></i> 支付宝</a>
              </li>
              <li role="presentation" class="">
                <a href="#wechatpay" role="tab" id="wechatpay-tab" data-toggle="tab" aria-controls="wechatpay" aria-expanded="false"><i class="icon icon-wepay"></i> 微信支付</a>
              </li>
            </ul>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>



</main>

  <footer class="footer" itemscope itemtype="http://schema.org/WPFooter">
	
	
    <ul class="social-links">
    	
        <li><a href="https://github.com/jirryji" target="_blank" title="Github" data-toggle=tooltip data-placement=top><i class="icon icon-github"></i></a></li>
        
        <li><a href="https://weibo.com/7355950025" target="_blank" title="Weibo" data-toggle=tooltip data-placement=top><i class="icon icon-weibo"></i></a></li>
        
        <li><a href="/blog/atom.xml" target="_blank" title="Rss" data-toggle=tooltip data-placement=top><i class="icon icon-rss"></i></a></li>
        
    </ul>

    <div class="copyright">
    	
        &copy; 2020 Jirry
        
        <div class="publishby">
        	Theme by <a href="https://github.com/cofess" target="_blank"> cofess </a>base on <a href="https://github.com/cofess/hexo-theme-pure" target="_blank">pure</a>.
        </div>
    </div>
</footer>
  <script src="//cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js"></script>
<script>
window.jQuery || document.write('<script src="js/jquery.min.js"><\/script>')
</script>

<script src="/blog/js/plugin.min.js"></script>


<script src="/blog/js/application.js"></script>


    <script>
(function (window) {
    var INSIGHT_CONFIG = {
        TRANSLATION: {
            POSTS: '文章',
            PAGES: '页面',
            CATEGORIES: '分类',
            TAGS: '标签',
            UNTITLED: '(未命名)',
        },
        ROOT_URL: '/blog/',
        CONTENT_URL: '/blog/content.json',
    };
    window.INSIGHT_CONFIG = INSIGHT_CONFIG;
})(window);
</script>

<script src="/blog/js/insight.js"></script>






   
<script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>





   
    
  <script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
  <script src="//cdn.jsdelivr.net/npm/valine"></script>
  <script type="text/javascript">
  var GUEST = ['nick', 'mail', 'link'];
  var meta = 'nick,mail,link';
  meta = meta.split(',').filter(function(item) {
    return GUEST.indexOf(item) > -1;
  });
  new Valine({
    el: '#vcomments',
    verify: false,
    notify: false,
    appId: '',
    appKey: '',
    placeholder: 'Just go go',
    avatar: 'mm',
    meta: meta,
    pageSize: '10' || 10,
    visitor: false
  });
  </script>

     







</body>
</html>